package com.zhzh.StudySpringBoot.service.impl;

import com.zhzh.StudySpringBoot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 *
 *
 * @author zhangzhen
 * @version C10 2018年02月02日 
 * @since SDP V300R003C10
 */
@Service
public class UserServiceImpl implements UserService
{

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void create(String name, Integer age) {
        jdbcTemplate.update("insert into user(NAME, AGE) values(?, ?)", name, age);
    }

    @Override
    public void deleteByName(String name) {
        jdbcTemplate.update("delete from user where NAME = ?", name);
    }

    @Override
    public Integer getAllUsers() {
        return jdbcTemplate.queryForObject("select count(1) from user", Integer.class);
    }

    @Override
    public void deleteAllUsers() {
        jdbcTemplate.update("delete from USER");
    }

    @Override
    public void getUserByName(String name)
    {
        //return jdbcTemplate.query("select * from USER where nickname=?", name);
    }
}
